package com.zk.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zk.yygh.hosp.result.Result;
import com.zk.yygh.model.user.Patient;
import com.zk.yygh.model.user.UserInfo;
import com.zk.yygh.user.service.UserInfoService;
import com.zk.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: 张凯
 * @date: 2022/6/18 - 20:45
 */
@Api("平台用户管理")
@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    //注意：加requestBody的前提是post请求，后端为data
    //注意：不加requestBody以get方式提交，后端是params
    @ApiOperation(value = "分页查询用户")
    @GetMapping("/{page}/{limit}")
    public Result selectPage(@PathVariable("page") Integer page,
                             @PathVariable("limit") Integer limit,
                             UserInfoQueryVo userInfoQueryVo){
        //封装分页查询参数
        Page<UserInfo> pageParam=new Page<>(page,limit);
        //调用service层进行查询
        IPage<UserInfo> pageModel=userInfoService.selectPage(pageParam,userInfoQueryVo);
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "用户锁定和解锁")
    @GetMapping("lock/{id}/{status}")
    public Result lock(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        userInfoService.lock(id,status);
        return Result.ok();
    }

    @ApiOperation(value = "用户详情")
    @GetMapping("detail/{userId}")
    public Result detail(@PathVariable("userId") Long userId){
        Map<String, Object> map = userInfoService.showDetail(userId);
        return Result.ok(map);
    }

    @ApiOperation("用户审批列表")
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable("userId") Long userId,@PathVariable("authStatus") Integer authStatus){
        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }
}
